using System;
using System.Collections.Generic;
using System.Text;

namespace Spike.ContractBuilder.Host
{
    public class RandomHostService
    {
        static Random r = new Random();
        public static object GetObject(Type type)
        {
            // type code
            switch (type.FullName)
            {
                case "System.Boolean":
                    return r.Next(0, 1) == 1;
                case "System.Single":
                case "System.Double":
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                    return r.Next(1000);
                case "System.DateTime":
                    return DateTime.Now.AddMinutes(r.Next(400000) - 200000);
                case "System.String":
                    return "Stub returned a value of " + r.Next(1000).ToString() + ".";
            }

            // should now be a reference type or array

            // ending code
            if (type.IsArray == false)
            {
                return type.GetConstructor(new Type[] { }).Invoke(null);
            }
            else
            {
                // TODO: a better array than this...
                return Array.CreateInstance(type.GetElementType(), 0);
            }
        }        
    }
}
